﻿using GuessTheAnswer.Model.Answer;

namespace GuessTheAnswer.Model.Subject;


/// <summary>
/// 单选题
/// </summary>
public class SingleChoiceSubject : ISubject
{
    public string TypeName => "单选题";

    public IAnswerRound CreateRound() => new SingleChoiceRound();
}

/// <summary>
/// 单选回合
/// </summary>
internal class SingleChoiceRound : IAnswerRound
{
    /// <summary>
    /// 结果列表
    /// </summary>
    private static readonly string[] ResultList = new string[] { "A", "B", "C", "D", "E", "F" };

    /// <summary>
    /// 回合作答结果
    /// </summary>
    private readonly string[] RoundResult = new string[ResultList.Length];



    public int RoundNumber { get; private set; } = 0;
    public bool IsCorrect { get; private set; }


    public void Last()
    {
        if (RoundNumber - 1 < 0)
        {
            throw new Exception("回合小于最小值");
        }

        IsCorrect = false;
    }

    public void Next()
    {
        if (IsCorrect) return;


        if (RoundNumber >= ResultList.Length)
        {
            throw new Exception("回合超出可猜测范围");
        }

        RoundResult[RoundNumber] = ResultList[RoundNumber];

        RoundNumber++;
    }

    public string RoundAnswer() => ResultList[RoundNumber];

    public void Correct()
    {
        IsCorrect = true;
    }
}